package com.imooc.sell.dao;

import com.imooc.sell.dataobject.SellBySeason;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface SeasonStatDao extends JpaRepository<SellBySeason, Integer> {
    /**
     * 获取最新的一条季度统计记录
     */
    @Query(value = "SELECT * FROM sell_by_season ORDER BY stat_by_season_id DESC limit 1", nativeQuery = true)
    SellBySeason findLatestSeasonData();

    /**
     * 统计最新的两条季度统计数据
     */
    @Query(value = "SELECT  * FROM sell_by_season ORDER BY update_time DESC limit 0,2", nativeQuery = true)
    List<SellBySeason> findLatest2Records();

    /**
     * 按时间范围查询并分页
     */
    Page<SellBySeason> findByUpdateTimeBetween(Date date1, Date date2, Pageable pageable);
}
